<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      // 手写falt
      // 如果是数组就递归,把函数的执行结果合起来,如果不是数组就直接push
      function flat(list) {
        let result = [];
        for (let i = 0; i < list.length; i++) {
          const item = list[i];
          if (Array.isArray(item)) {
            result = [...result, ...flat(item)];
          } else {
            result = [...result, item];
          }
        }
        return result;
      }
      const a = flat([1, [2, [4]], [6, 7]]);
      console.log(a);
    </script>
  </body>
</html>
